#ifndef MATERIALACCESS_H
#define MATERIALACCESS_H

#include "style/styledtableview.h"
#include "style/styledtreeview.h"
#include "service/materialservice.h"
#include <QWidget>
#include <QList>
#include <QMap>
#include <QVariant>

QT_BEGIN_NAMESPACE
namespace Ui { class MaterialAccess; }
QT_END_NAMESPACE

class MaterialAccess : public QWidget
{
    Q_OBJECT

public:
    MaterialAccess(QWidget *parent = nullptr);
    ~MaterialAccess();

private slots:
    void onTableButtonClicked(const QString& operation, int materialId, int quantity, int row);
    void onTreeNodeClicked(const QString& nodeId, const QMap<QString, QString>& nodeData);
    void loadMaterialData();

private:
    Ui::MaterialAccess *ui;
    StyledTableView *m_materialTableWidget;
    StyledTreeView *m_materialTreeWidget;
    // 变更：使用QList<QMap<QString, QVariant>>存储数据
    QList<MaterialVO*> m_materialDataList;
    MaterialService* m_materialService;

    void initUI();
    void initConnections();
    // 变更：生成QMap类型的测试数据
    void generateMaterialData();
    QList<QMap<QString, QString>> generateTreeData();
    void refreshMaterialData();
    void showOperationMessage(bool success, const QString& successMsg, const QString& errorMsg);
};
#endif // MATERIALACCESS_H
